<template>
  <div class="tableCss">
    <el-form class="app-container-query" :model="queryParams" ref="queryParamsRef" size="small" :inline="true">
      <el-form-item label="检测报告">
        <el-input placeholder="请输入" v-model="queryParams.report" clearable @keyup.enter.native="getList"></el-input>
      </el-form-item>
      <el-form-item label="提醒类型">
        <el-select v-model="queryParams.warnType" clearable>
          <el-option v-for="item in warnTypeOption" :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="到期时间">
        <el-date-picker type="daterange" v-model="queryParams.rangeTime" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" @change="daterangeChange"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getList">查询</el-button>
        <el-button @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table border header-cell-class-name="bg-F4F8FF"
    :data="tableData"
    max-height="560"
    v-loading="loading"
    >
      <el-table-column align="center" label="检测报告" prop="report">
        <template #default="scope">
          <TableFilesBtn :files="scope.row.report.split(',')" v-if="scope.row.report"/>
        </template>
      </el-table-column>
      <el-table-column align="center" label="提醒类型" prop="warnType">
        <template #default="scope">
          {{ warnTypeMap[scope.row.warnType] }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="到期时间" prop="deadline"></el-table-column>
      <el-table-column align="center" label="操作" width="200">
        <template #default="scope">
          <div class="tableBtnCss">
            <el-button type="text" @click="dealWithClickBtn(scope.row)">处置</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      style="margin-top:10px;text-align: right;"
      background
      :pageSize="queryParams.pageSize"
      :current-page="queryParams.pageNum"
      layout="prev, pager, next"
      :page-sizes="[10, 20, 50]"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange">
    </el-pagination>
  </div>
</template>

<script>
import { checkReportDeadlineListApi } from '@/api/zhangping/drinkWater'
export default {
  props:{
    tabActiveId:{
      type:[Number, String]
    },
    cmpFrom:{
      type: String,
      default:()=> 'second'
    },
  },
  data(){
    return{
      queryParams: {
        pageNum:1,
        pageSize:10,
        report: null,
        warnType: null,
        rangeTime: null,
        beginTime:null,
        endTime:null,
      },
      tableData:[],
      total:0,
      warnTypeOption:[{value:'0',label:'提醒'},{value:'1',label:'关闭提醒'},],
      warnTypeMap:{'0':'提醒','1':'关闭提醒',},
    }
  },
  mounted(){
  },
  methods:{
    daterangeChange(val){
      this.queryParams.beginTime = val[0]
      this.queryParams.endTime = val[1]
    },
    dealWithClickBtn(row){
      this.$router.push({path:`/secondary/${this.cmpFrom}/report`,query:{from:'test',cmpFrom:this.cmpFrom}})
      sessionStorage.setItem('tabActiveId',this.tabActiveId)
    },
    resetQuery() {
      for(let key in this.queryParams){
        this.queryParams[key] = null
      }
      this.queryParams.pageNum = 1
      this.queryParams.pageSize = 10
      this.getList()
    },
    async getList(){
      this.loading = true
      const query = {
        ...this.queryParams,
      }
      if( query.rangeTime ){
        delete query.rangeTime
      }
      const { code, rows, total} = await checkReportDeadlineListApi( query )
      if( code === 200 ){
        this.tableData = rows
        this.total = total
      }
      this.loading = false
    },
    handleCurrentChange(val){
      this.queryParams.pageNum = val
      this.getList()
    },
    handleSizeChange(val){
      this.queryParams.pageSize = val
      this.getList()
    },
  },
}
</script>

<style scoped lang="scss">
.tableCss{
  .app-container-query{
    padding: 18px 0;
    margin-bottom: -18px;
  }
  .tableBtnCss{
    flex-wrap: wrap;
    display: flex;
    column-gap: 10px;
    justify-content: center;
  }
}
</style>